package uav.util.deepsort;

public class UavUtil {
    // 计算两个交并比
    public static float calculateIoU(Detection box1, Detection box2) {
        float x1 = Math.max(box1.getX1(), box2.getX1());
        float y1 = Math.max(box1.getY1(), box2.getY1());
        float x2 = Math.min(box1.getX2(), box2.getX2());
        float y2 = Math.min(box1.getY2(), box2.getY2());
        float intersectionArea = Math.max(0, x2 - x1 + 1) * Math.max(0, y2 - y1 + 1);
        float box1Area = (box1.getX2() - box1.getX1() + 1) * (box1.getY2() - box1.getY1() + 1);
        float box2Area = (box2.getX2() - box2.getX1() + 1) * (box2.getY2() - box2.getY1() + 1);
        float unionArea = box1Area + box2Area - intersectionArea;
        return intersectionArea / unionArea;
    }
}
